<?php

class SingletonTimer {
	
	private static $instance;
	private static $start = 0;
	private static $finish = 0;
	
	// A private constructor; prevents direct creation of object
	private function __construct() { }
	
	// singleton method
	public static function get_instance() {
		if (!isset(self::$instance)) {
			$c = __CLASS__;
			self::$instance = new $c;
		}
		return self::$instance;
	}

	// Prevent users to clone the instance
	public function __clone() {
		trigger_error('Clone is not allowed.', E_USER_ERROR);
	}
	
	public function start_timer() {
		$time = microtime(); 
		$time = explode(" ", $time); 
		$time = $time[1] + $time[0]; 
		$start = $time;
	}
	
	public function end_timer() {
		$time = microtime(); 
		$time = explode(" ", $time); 
		$time = $time[1] + $time[0]; 
		$finish = $time; 
	}
	
	public function get_time() {
		return ($finish - $start);
	}
}

?>
